package com.cg.config;

import com.cg.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                // 需要登录的接口
                .addPathPatterns("/ai/saveAiTalks", "/ai/clearAiTalks", "/userInfo",
                        // 写操作需登录
                        "/job/like/**", "/job/favorite/**")
                // 排除不需要登录的接口（AI聊天接口通过URL参数验证token）
                .excludePathPatterns("/login", "/register", "/health", "/ai/chat",
                        // 点赞/收藏统计允许匿名访问（GET）
                        "/job/likes/**", "/job/favorites/**");
    }
}

